package a;

import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author: jzw
 * @Description
 * @date: 2022/11/15 23:40
 */
public class d1115 {
    public static void main(String[] args) throws IOException, IllegalAccessException, ParseException {
        /*String path = "F:\\iot\\d";
        File dir = new File(path);
        List<File> allFileList = new ArrayList<>();

        // 判断文件夹是否存在
        if (!dir.exists()) {
            System.out.println("目录不存在");
            return;
        }
        getAllFile(dir, allFileList);

        List<Map<String, Integer>> mapList = new ArrayList<>();

        for (File file : allFileList) {
            int totalLines = getTotalLines(file.getAbsolutePath(), null);
        }*/
        String start = "20221124110212";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        String format = simpleDateFormat.format(new Date());
        Date parse = simpleDateFormat.parse(start);
        System.out.println(format);
        System.out.println(parse);
        System.out.println(LocalDateTime.now());

    }

    //获取目录下文件及其子目录文件
    public static void getAllFile(File fileInput, List<File> allFileList) {
        // 获取文件列表
        File[] fileList = fileInput.listFiles();
        assert fileList != null;
        for (File file : fileList) {
            if (file.isDirectory()) {
                // 递归处理文件夹
                // 如果不想统计子文件夹则可以将下一行注释掉
                getAllFile(file, allFileList);
            } else {
                // 如果是文件则将其加入到文件数组中
                allFileList.add(file);
            }
        }
    }

    static int getTotalLines(String fileName, Map<String, Integer> map) throws IOException, IllegalAccessException {

        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); //使用缓冲区的方法将数据读入到缓冲区中
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("F:\\iot\\iccid.txt"));
        LineNumberReader reader = new LineNumberReader(br);
        String s = reader.readLine(); //定义行数
        int lines = 0;
        while (s != null) //确定行数
        {
            s = reader.readLine();
            String line = readLine(s);
            bufferedWriter.write(line);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }
        reader.close();
        br.close();
        System.out.println("\n文件名：" + fileName + "\t该文件总行数：" + lines);
//        log.info("文件名：{}\t该文件总行数：{}", fileName, lines);
        return lines; //返回行数
    }

    public static String readLine(String line) {
        String[] split = line.split(",");
        String s = split[1];
        String[] split1 = s.split(":");
        return split1[1];
    }
}
